﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using eProject.Logic;
using eProject.Model;

namespace ViewModel
{
    public class ActivityViewModel : BaseViewModel
    {
        private readonly Activities _activities;
        private readonly Activity _activity;

        public ActivityViewModel(Activities activities, Activity activity)
        {
            _activities = activities;
            _activity = activity;
            _activities.ManHoursChanged += OnManHoursChanged;
        }

        public Task Task { get { return _activity.Task; } }

        public Employee Employee { get { return _activity.Employee; } }

        public Period Period 
        { 
            get { return _activity.Period; }
            set
            {
                if (value == _activity.Period) return;

                _activity.Period = value;
                InvokePropertyChanged("Period");
            }
        }

        public int Priority
        {
            get { return _activity.Priority; }
            set
            {
                if (value == _activity.Priority) return;

                _activity.Priority = value;
                InvokePropertyChanged("Priority");
            }
        }

        public double ManHours
        {
            get { return _activities.GetManHours(_activity); }
        }

        private void OnManHoursChanged(IEnumerable<Activity> activities)
        {
            if (activities.Contains(_activity))
            {
                InvokePropertyChanged("ManHours");
            }
        }

    }
}
